/*
* url:home.jsp
* name:个人主工作台
* id:0000
*/
function openFile(url,name,id)
{
	var tabPrefix = "tab_";
	var panelPrefix = "panel_";
	var iframePrefix = "iframe_";
	
	var self = $("#main");
	var list = $("#main").children('ul:first');
	var lis = $('li:has(a[href])', list);
	var anchors = lis.map(function() { return $('a', $("#main"))[0]; });
	var panels = $("#main").children('div');
	
	$("#main div iframe").attr("height","0");
	
	var iframeHeight = $("#main").innerHeight() - $("#tabList").outerHeight(true);
	if($("#"+tabPrefix+id).size()>0)
	{
		$("#"+tabPrefix+id).click();
	}
	else
	{
		//如果超过了一个横向显示的Tab头，则提示关闭多余页面
		
		var tabItems =parseInt( $("#tabList").width()/100);
		
		if($("#tabList li").size()>=tabItems&&tabItems>0)
		{
			
			alert('打开的标签页过多，请双击标签头关闭闲置的标签页');
			return false;
		}
		
		
		lis.removeClass("ui-tabs-selected").removeClass("ui-state-active");
		var liElement = $("<li></li>").addClass("ui-tabs-selected ui-state-active");
		
		$("<a></a>").attr("id",tabPrefix+id).attr("href",url).html(name).appendTo(liElement).click(function(){
		
		
			var id = $(this).attr("id").replace(tabPrefix,"");
			
			$(this).parent().parent().children("li").removeClass("ui-tabs-selected").removeClass("ui-state-active");
			$(this).parent().addClass("ui-tabs-selected ui-state-active");
			
			$("#main div").addClass("ui-tabs-hide");
			$("#main div").children("iframe").attr("height","0");
			$("#"+iframePrefix + id).attr("height",iframeHeight);
			$("#"+iframePrefix + id).parent().removeClass("ui-tabs-hide");
			return false;
		}).dblclick(function(){
			if($("#tabList li").size() <=1)
			{
				alert("最后一个标签页，不允许关闭");
				return false;
			}
			
			var id = $(this).attr("id").replace(tabPrefix,"");
			
			$("#"+tabPrefix+id).parent().prev("'li:has(a[href])").children("a").click();
			
			$("#"+tabPrefix+id).parent("li").remove();
			$("#"+iframePrefix+id).parent("div").remove();
		});
		
		liElement.appendTo(list);
		
		var newPanel = $("<div></div>").addClass("ui-tabs-panel ui-widget-content ui-corner-bottom");// 
		
		//1,如果URL中包含?则url=url+"&functionID="+功能编号，
		//2，否则url = url+"?functionID="+功能编号
		if(url.indexOf(".jsp") != -1){
			
		}else if(url.indexOf("?") == -1){
			url = url + "?functionId=" + id;
		}else{
			url = url + "&functionId=" + id;
		}
		
		$("<iframe frameborder=\"0\" width=\"100%\" ></iframe>").attr("height",iframeHeight).attr("id",iframePrefix+id).attr("name",iframePrefix+id).attr("src",url).appendTo(newPanel);
		
		newPanel.appendTo($("#main"));
	}
	
	
	
	//$("#mainTop").html(name);
	//$("#mainFrame").attr("src",file);
	//$("#mainFrame").attr("rel",id);
	
	//<iframe name="mainFrame" id="mainFrame"  frameborder="0"  src="home.jsp" width="100%" height="540"></iframe>
	
	
	
	
} 



function init()
{
//	var bodyHeight = $(window).height();
//	var bodyWidth  = $(window).width();
//	
//	
//	var titleHeight = $("#title").outerHeight(true);
//	var titleWidth = $("#title").outerWidth(true);
//	
//	
//	
//	
//	$("#menu").height(bodyHeight - titleHeight -  4);
//	
//	$("#menuPanel").height($("#menu").height() - $("#menuTop").outerHeight());
//	
//	
//	var menuWidth = $("#menu").outerWidth(true);
//	
//	
//	
//	$("#main").height(bodyHeight - titleHeight - 4 - px2num($("#main").css("marginTop"))- px2num($("#main").css("marginBottom")));
//	$("#main").width(bodyWidth - menuWidth  - 4);
//
//	
//	$("#mainPanel").height($("#main").height() - $("#mainTop").outerHeight());
//	$("#mainPanel iframe").attr("height",$("#mainPanel").innerHeight());
//	
	
}



function updatePassword()
{
		var oldPassword = $("#oldPassword").val();
		var newPassword = $("#newPassword").val();
		var confirmPassword = $("#confirmPassword").val();
		
		
		if($.trim(oldPassword).length === 0)
		{
			alert("旧密码不能为空");
			$("#oldPassword").focus();
			return;
		}
		
		if($.trim(newPassword).length === 0)
		{
			alert("新密码不能为空");
			$("#newPassword").focus();
			return;
		}
		
		if($.trim(confirmPassword).length === 0)
		{
			alert("确认新密码不能为空");
			$("#confirmPassword").focus();
			return;
		}
		
		if(oldPassword === newPassword)
		{
			alert("旧密码与新密码一致，无需进行修改操作");
			return;
		}
		
		if(newPassword != confirmPassword)
		{
			alert("新密码与确认密码不一致，请重新输入");
			$("#newPassword").focus();
			return;
		}
		
		$.post(
			"operator.do?type=modifyPassword",
			{
				operatorID:$("#operatorID").val(),
				oldPassword:oldPassword,
				newPassword:newPassword,
				confirmPassword:confirmPassword
			},
			function(xml)
			{
				var flag = parseInt($(xml).find("flag").text());
				var body = $(xml).find("body").text();
				
				if(flag === 1)
				{
					//modify success
					alert(body);
					$("#modifyPasswordContent").dialog("close");
				}
				else
				{
					//modify fail
					alert(body);
				}
			},
			"xml"
		);
}
	
$(function(){
	
	$("#exitButton").click(function(){
		//window.close();
		if(window.confirm("确认退出?") == true)
		{
			window.location.href = "operator.do?type=logout";
		}
		
	});
	

	
	
	$("body").attr("scroll","no");
	init();
		
	$(window).resize(function(){
		init();
	});
	$('#menuPanel').fileTree({root: '00', script: 'function.do' }, function(file,name,id) { 
      		openFile(file,name,id);  
    });
    
    openFile("home.jsp","个人工作台","0000")
    
    /************* modify password *****************/
    
     $("#modifyPasswordContent").dialog({
     		bgiframe: true,
			autoOpen:false,
			resizable:false,			
			width:310,
			stack:false,
			modal:true,
			position:'center',			
			title:'密码修改',
			buttons:{"取消":function(){$("#modifyPasswordContent").dialog("close");},"保存":updatePassword}
     });
     
     
	 /************* modify password *****************/  
	 
	$('body').layout({ applyDefaultStyles: true });
	
	
	
});


